package com.totoro.service.impl;

import com.totoro.pojo.Category;
import com.totoro.mapper.CategoryMapper;
import com.totoro.service.CategoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author TOTORO
 * @date 2021/5/18 16:07
 * 分类service接口实现类
 */
@Service
public class CategoryServiceImpl implements CategoryService {

    @Autowired
    CategoryMapper categoryMapper;

    @Override
    public List<Category> findOneLevel() {
        return categoryMapper.findOneLevel();
    }

    @Override
    public List<Category> findTwoLevel(String like) {
        return categoryMapper.findTwoLevel(like);
    }

    @Override
    public List<Category> findThreeLevel(String like) {
        return categoryMapper.findThreeLevel(like);
    }

    @Override
    public List<Category> findFourOrFiveLevel(String like) {
        return categoryMapper.findFourOrFiveLevel(like);
    }

    @Override
    public Map<Integer, Category> findKeywordData(String like) {
        List<Category> categoryList = (List<Category>) categoryMapper.findKeywordData("%"+like+"%");
        Map<Integer, Category> map = new HashMap<>();
        for (int i = 0; i < categoryList.size(); i++) {
            map.put(i, categoryList.get(i));
        }
        return map;
    }

    @Override
    public String byIdFindCategoryName(int id) {
        return categoryMapper.byIdFindCategoryName(id).get(0).getName();
    }

    @Override
    public List<Category> underNameCheck(String name) {
        return categoryMapper.underNameCheck(name);
    }

    @Override
    public boolean findIsBy(int cid) {
        return categoryMapper.findIsBy(cid)==0?false:true;
    }

    @Override
    public List<Category> findIsHaveSpuAttr(int cid) {
        return categoryMapper.findIsHaveSpuAttr(cid);
    }

    @Override
    public Category byIdFindCategory(int id) {
        return categoryMapper.byIdFindCategoryName(id).get(0);
    }

    @Override
    public Integer updateBuyCounyByCid(int cid) {
        return categoryMapper.updateBuyCounyByCid(cid);
    }

    @Override
    public List<Category> findCategoryByCategoryIds(Integer[] categoryIds) {
        return categoryMapper.findCategoryByCategoryIds(categoryIds);
    }

    @Override
    public List<Category> findAllTwoCategory() {
        return categoryMapper.findAllTwoCategory();
    }
}
